/**
 * Created by lihao on 2017/6/28.
 */
const keystone = require('keystone');
const Promise = require('bluebird');
const _ = require('lodash');
const Post = keystone.list('User');
exports = module.exports = function (req, res) {
    let reqQuery = _.omit(_.assign(req.query, req.body, req.param), []);
    let omitFueld = ['password', 'isAdmin', '__v'];
    let optionalExpression = _.transform(omitFueld, function (r, val) {
        r[val] = 0;
    }, {});
    if (_.has(reqQuery, 'id') && reqQuery.id != '') {
        Post.model.findById(reqQuery.id).exec(function (err, item) {
            if (err) return res.json({code: 0, message: '请求失败'});
            if (_.isEmpty(item)) return res.json({code: 0, message: '找不到用户'});
            item.getUpdateHandler(req).process({status:'delete'}, { flashErrors: true, logErrors: true }, function(err) {
                if (err) return res.json({code: 0, message: '删除失败'});
                return res.json({code: 1, message: '删除成功'});
            });

        });

    } else {
        return res.json({code: 0, message: '用户ID为空'});
    }

};
